<?php

class List_product extends Public_Controller {

    protected $_list;

    public function __construct() {
        parent::__construct();
        $this->_load();
    }

    public function index() {
        $this->_replacePhrase();
    }

    private function _load() {
        $this->load->helper(array('url', 'form'));
        $this->load->model(array('user', 'product'));
        $this->_getList();
    }

    private function _replacePhrase() {
        $this->lang->load('public/general', $this->_slang_name);
        ////////////////////////
        $this->lang->load('public/register', $this->_slang_name);
        $this->_adata['sloginFail'] = $this->_serror;
        $this->_adata['list'] = $this->_list;
        $this->_adata['userLog'] = $this->session->userdata($this->config->item('data_login'));
        $this->_adata['security'] = (object) array('token_name' => $this->security->get_csrf_token_name(),
                    'token' => $this->security->get_csrf_hash());
        $this->fill_phrase('product', $this->_adata, $this->lang->language);
    }

    private function _getList() {
        $this->load->library('pagination');

        $aConfig = array(
            'base_url' => site_url('product/list_product/index/'),
            'per_page' => 10,
            'uri_segment' => 4,
            'num_links' => 6,
            'total_rows' => $this->product->countProduct(),
            'cur_tag_open' => '<li><span><a class="normal-text">',
            'cur_tag_close' => '</a></span></li>',
            'num_tag_open' => '<li>',
            'num_tag_close' => '</li>',
            'use_page_numbers' => true,
            'next_link' => '»',
            'prev_link' => '«',
            'prev_tag_open' => '<li>',
            'prev_tag_close' => '</li>',
            'first_tag_open' => '<li>',
            'first_tag_close' => '</li>',
            'last_tag_open' => '<li>',
            'last_tag_close' => '</li>',
            'last_link' => 'Last',
            'first_link' => 'First',
            'next_tag_open' => '<li>',
            'next_tag_close' => '</li>',
            'previous_tag_open' => '<li>',
            'previous_tag_close' => '</li>'
        );

        //page number.
        $page = $this->uri->segment(4);
        //Get offset
        $offset = ((!empty($page) ? $this->uri->segment(4) : 1) - 1 ) * $aConfig['per_page'];
        $this->pagination->initialize($aConfig);
        $this->_adata['pages'] = $this->pagination->create_links();
        $this->_list = $this->product->gets($offset, $aConfig['per_page']);
    }

}

?>
 